﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BMS.Syncro.Devices.Dao.Interfaces;

namespace BMS.Syncro.Devices.Dao
{
    public class ConfigurationDaoNHibernate : IDaoHelper<BMS.Syncro.Devices.Model.Entities.MachineConfiguration>
    {
        private NHibernate.Cfg.Configuration myConfiguration;
        private NHibernate.ISessionFactory mySessionFactory;
        private NHibernate.ISession mySession;

        public ConfigurationDaoNHibernate()
        {
            myConfiguration = new NHibernate.Cfg.Configuration();
            myConfiguration.Configure();
            mySessionFactory = myConfiguration.BuildSessionFactory();
            mySession = mySessionFactory.OpenSession();
        }

        #region IDaoHelper<Visitor> Members

        public void Save(BMS.Syncro.Devices.Model.Entities.MachineConfiguration persistenceObject)
        {
            // Add Record
            using (mySession.BeginTransaction())
            {
                mySession.Save(persistenceObject);

                mySession.Transaction.Commit();
            }
        }

        public void Update(BMS.Syncro.Devices.Model.Entities.MachineConfiguration persistenceObject)
        {
            throw new NotImplementedException();
        }

        public void Delete(BMS.Syncro.Devices.Model.Entities.MachineConfiguration persistenceObject)
        {
            throw new NotImplementedException();
        }

        public BMS.Syncro.Devices.Model.Entities.MachineConfiguration Get(string propertyName, string value)
        {
            throw new NotImplementedException();
        }

        public List<BMS.Syncro.Devices.Model.Entities.MachineConfiguration> List()
        {
            using (mySession.BeginTransaction())
            {
                NHibernate.ICriteria criteria = mySession.CreateCriteria<BMS.Syncro.Devices.Model.Entities.MachineConfiguration>();
                IList<BMS.Syncro.Devices.Model.Entities.MachineConfiguration> list = criteria.List<BMS.Syncro.Devices.Model.Entities.MachineConfiguration>();
                mySession.Transaction.Commit();
                return (List<BMS.Syncro.Devices.Model.Entities.MachineConfiguration>)list;
            }
        }

        #endregion
    }
}
